/* 
 * Arcms，一个基于J2EE架构内容管理系统
 * Copyright © GrayRabbit Co., Ltd. All rights reserved.
 * Department:运营department
 * 更多信息请访问：
 * http://code.google.com/p/gray-rabbit-cms/
 */
package org.grayrabbit.cms.action.user;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.grayrabbit.cms.action.common.BaseAction;
import org.grayrabbit.cms.entity.Dictionary;
import org.grayrabbit.cms.entity.User;
import org.grayrabbit.cms.service.user.UserService;
import org.grayrabbit.cms.vo.user.UserBean;
import org.grayrabbit.dao.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

/**
 * <b>UserAction</b> Struts2 action�?





 * @version 1.0,创建时间:2011-05-16 16:04:46 
 */
@Controller
@Scope("prototype")
@Results( {
		@Result(name = "reload", type = "redirect", location = "user-list.action"),
		@Result(name = "input", type = "dispatcher", location = "user-input.jsp"),
		@Result(name = "success", type = "dispatcher", location = "user-list.jsp")
		}
		)
public class UserAction extends BaseAction<UserBean> {
	
	private static final long serialVersionUID = -1L;
	//Service接口接入
	@Autowired
	@Qualifier("userServiceImpl")
	private UserService userService;
	
	private List<Dictionary> isMale;
	private List<Dictionary> paperType;
	private List<Dictionary> familyList;
	private List<Dictionary> edcucationList;
	private String blackList;
	//VO对象，由前端页面数据组装
	private UserBean user;
	//分页对象
	private Page<User> page = new Page<User>(MAX_PAGE_NUM,true);

	/**
	 * 在执行（struts2的action调用时）list()方法前执行本方法
	 */
	public void prepareList(){
		prepareModel();
	}
	
	/**
	 * 在执行任何其它action方法（struts2的action调用时）前执行本方法
	 */
	public void prepare(){
		if(user==null){
			user = new UserBean();
		}
	}
	/**
	 * 实现ModelDriven的接口简例前端页的bean组装写法,
	 *  如：
	 *	<pre>
	 *		<code> name="user.userName"</code>
	 *	改写成：
	 *		<code> name="userName"</code>
	 *	action实例中，会自动组成user成员变量
	 *	</pre>
	 */
	public UserBean getModel() {
		return user;
	}
	
	@Override
	protected void prepareModel(){
		if(user!=null&&StringUtils.isNotBlank(user.getUserId())){
			user = (UserBean)dozer.map(userService.getUser(user.getUserId()),UserBean.class);
		}
		
	}

	/**
	 * 删除<b>User</b>记录的方法，成员变量<b>key</b>为主键的String数组，以主键方式进行删作
	 * 删除成功后，返回"reload"，然后跳转到user-list.action
	 */
	@Override
	@Action(value="user-delete"
			)
	public String delete(){
		userService.delete(key);
		return RELOAD;
	}
	
	/**
	 * User的列表方法，通过成员变量<b>page�?{insClassName}</b>调用service接口，更新page
	 * 执行成功后，将映射到user-list.jsp页面
	 */
	@Override
	@Action(value="user-list")
	public String list(){
		userService.list(page,user);
		return SUCCESS;
	}
	
	public List<Dictionary> getFamilyList() {
		return familyList;
	}

	public void setFamilyList(List<Dictionary> familyList) {
		this.familyList = familyList;
	}

	public List<Dictionary> getEdcucationList() {
		return edcucationList;
	}

	public void setEdcucationList(List<Dictionary> edcucationList) {
		this.edcucationList = edcucationList;
	}

	public List<Dictionary> getPaperType() {
		return paperType;
	}

	public void setPaperType(List<Dictionary> paperType) {
		this.paperType = paperType;
	}

	public List<Dictionary> getIsMale() {
		return isMale;
	}

	public void setIsMale(List<Dictionary> isMale) {
		this.isMale = isMale;
	}
	
	/**return 前端页面数据组装VO对象,<b>UserBean</b>*/
	public UserBean getUser() {
		return user;
	}

	public void setUser(UserBean user) {
		this.user = user;
	}
	
	/*
	 * return分页对象，默认实例化。如：page.pageNu=2,将更新相应的对象property
	 */
	public Page<User> getPage() {
		return page;
	}
	//接收前端form,url提交参数组装成分页property
	public void setPage(Page<User> page) {
		this.page = page;
	}

	public String getBlackList() {
		return blackList;
	}

	public void setBlackList(String blackList) {
		this.blackList = blackList;
	}
	
	@Override
	public String save() throws Exception {
		return null;
	}
	
}